import 'babel-polyfill';
import Vue from 'vue';
import App from './App.vue';
import router from '@/router';
// // 全局变量
// import global_ from '@/common/global';
// 状态管理
import store from './store';

// 表格扩展
import 'xe-utils';
import VXETable from 'vxe-table';
import VXETablePluginElement from 'vxe-table-plugin-element';
import 'vxe-table-plugin-element/dist/style.css';
// 样式库
import ElementUI from 'element-ui';
// 右键菜单
import VueContextMenu from '@xunlei/vue-context-menu';
// 封装组件库
import { PluginsPage } from '@yhfin/biz';
// 拖拽
import VueDraggable from 'vuedraggable';
// 表格多选框组件
import RiskTableSelection from '@/common/components/risk-table-selection.vue';
// 全局公共样式
import '@/assets/style/common.scss';
import '@/pages/layout/style/theme.scss';
// 请求
import axios from '@/utils/request';
import './permissions';
import './common/directives';
// markdown 编辑器
import mavonEditor from 'mavon-editor';
import 'mavon-editor/dist/css/index.css';

import Treeselect from '@riophae/vue-treeselect';
import '@riophae/vue-treeselect/dist/vue-treeselect.css';

import RiskVirtualSelect from '@/common/components/risk-virtual-select.vue';

import moment from 'moment';
moment.locale('zh-cn');

// Vue.prototype.$global = global_;
Vue.prototype.$axios = axios;
Vue.prototype.$moment = moment;
Vue.use(mavonEditor);
Vue.use(VXETable);
VXETable.use(VXETablePluginElement);
Vue.use(ElementUI);
Vue.use(VueContextMenu);
Vue.use(PluginsPage);
Vue.component('VueDraggable', VueDraggable);
Vue.component('RiskTableSelection', RiskTableSelection);
Vue.component('Treeselect', Treeselect);
Vue.component('RiskVirtualSelect', RiskVirtualSelect);

Vue.config.productionTip = false;

// 全局点击防抖处理
const on = Vue.prototype.$on;
Vue.prototype.$on = function(e, func) {
    // 目前只有点击需要防抖
    if (e === 'click') {
        let sto;
        on.call(this, e, function() {
            // eslint-disable-next-line prefer-rest-params
            sto ? clearTimeout(sto) : func.apply(this, arguments);
            // eslint-disable-next-line no-return-assign
            sto = setTimeout(() => (sto = undefined), 500);
            // 点击后移除焦点
            this.$el && this.$el.blur();
        });
    } else {
        on.call(this, e, func);
    }
};

/* eslint-disable no-new */
new Vue({
    el: '#app',
    router,
    store,
    render: h => h(App),
});
